using System;
using System.Collections.Generic;
using System.Linq;

namespace Mailias.UI.Web
{
    public class Message
    {
        public string Id { get; set; }
        public string From { get; set; }
        public string To { get; set; }
        public List<string> Headers { get; set; }
        public string Body { get; set; }
        public DateTime CreatedOn { get; set; }
        public bool FlaggedToBeDeleted { get; set; }


        public string GetSubject()
        {
            if (Headers != null)
            {
                var header = Headers.SingleOrDefault(h => h.ToLower().StartsWith("subject:"));
                if (!string.IsNullOrEmpty(header))
                {
                    return header.Substring(header.IndexOf(":") + 1)
                        .Trim();
                }
            }
            return null;

        }

        public string GetToForDisplay()
        {
            return To.Trim("< >".ToCharArray());
        }

        public Message()
        {
            Headers = new List<string>();
            CreatedOn = DateTime.Now;
            FlaggedToBeDeleted = false;
        }
    }
}